package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseAuditApi;
import com.xuecheng.api.content.model.dto.CourseBaseDTO;
import com.xuecheng.api.content.model.qo.QueryCourseModel;
import com.xuecheng.api.content.model.vo.CourseAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.content.convert.CourseBaseConvert;
import com.xuecheng.content.service.CourseBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author by 高鹏
 * @Date 2021/12/13
 * @Description
 */
@RestController
public class CourseAuditController implements CourseAuditApi {


    public static final Long OPERATION_FLAG = -88998877L;

    @Autowired
    private CourseBaseService courseBaseService;

    /**
     * 课程基础信息条件分页查询-运营
     * @param params
     * @param model
     * @return
     */
    @PostMapping("/m/course/list")
    @Override
    public PageVO queryCourseList(PageRequestParams params, @RequestBody QueryCourseModel model) {

        PageVO pageVO = courseBaseService.queryCourseList(params, model, OPERATION_FLAG);

        return pageVO;
    }


    /**
     * 课程审核(提交的课程才可审核)
     * @param auditVO
     */
    @PostMapping("/m/courseReview/approve")
    @Override
    public void approveCourse(@RequestBody CourseAuditVO auditVO) {
        //将 vo 转为 dto 数据
        CourseBaseDTO dto = CourseBaseConvert.INSTANCE.auditVo2dto(auditVO);

        //调用service方法进行课程审核
        courseBaseService.approve(dto);
    }
}
